package v1

import (
	"github.com/gin-gonic/gin"
	"rest/middleware"
	"rest/services"
)

func Router() *gin.Engine {
	router := gin.Default()
	// 使用跨域中间件
	router.Use(middleware.Cors())
	// 给表单限制上传大小 (默认是 32 MiB)
	router.MaxMultipartMemory = 8 << 20 // 8 MiB
	// gin中解析模板

	//router.LoadHTMLGlob("templates/*")

	// 拆分路由为V1版本 ==> user模块
	V1RouterGroup := router.Group("/v1")
	{
		userRouterGroup := V1RouterGroup.Group("/user")
		userRouterGroup.POST("/userlogin", services.Login)
		userRouterGroup.GET("/userlist", services.ReturnUserList)
		userRouterGroup.POST("/getemailcode", services.ReturnEmailCode)
		userRouterGroup.POST("/loginbyemail", services.LoginByEmail)
		userRouterGroup.POST("/deluser", services.DelUser)
		userRouterGroup.GET("/test", services.Test)
	}
	return router
}
